package Opera;

import BOOK.Book;
import BOOK.Booklist;

import java.util.Scanner;

public class FindOperation implements IOPeration{
    @Override
    public void work(Booklist booklist) {
        System.out.println("查找图书！");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入查找的书名:");
        String booksname = scanner.nextLine();
        int currentSized = booklist.getUsedSize();
        for (int i = 0;i < currentSized; i++){
            /*System.out.println(booklist[i]);
            不可以通过这样的写法来打印数组中的每一个元素，因为“booklist”不是数组，booklist中的“books”才是数组*/
            Book book = booklist.getBook(i);//接受返回的数组对象
            if (book.getName().equals(booksname)){
                System.out.println("找到了这本书：");
                System.out.println(book);
                return;
            }
        }
        System.out.println("没有这本书");
    }

    //将下列这个操作抽象出来到IOPeration接口
/*    public void word(Booklist booklist){
        System.out.println("查找图书！");
    }*/
}
